$(document).ready(function(){
	initUsers();
});



//	获取所有用户
	function showUsers(usersList){
		for (var i=0;i<usersList.length;i++){
			if(usersList[i].status == 0){
				$("#usersList").append('<tr id="user_'+usersList[i].id+'"><td>'+usersList[i].name+'</td><td>'+usersList[i].hb+'</td><td>'+usersList[i].exp+'</td><td class="status">封 停</td><td><a href="userInfo.html?id='+usersList[i].id+'"><button>详 情</button></a><button class="addUser" onclick="addUser(this)">解 封</button><button onclick="delUser(this)" class="delUser" style="display:none;">封 停</button></td></tr>');
			}else{
				$("#usersList").append('<tr id="user_'+usersList[i].id+'"><td>'+usersList[i].name+'</td><td>'+usersList[i].hb+'</td><td>'+usersList[i].exp+'</td><td class="status">正 常</td><td><a href="userInfo.html?id='+usersList[i].id+'"><button>详 情</button></a><button class="addUser" onclick="addUser(this)" style="display:none;">解 封</button><button onclick="delUser(this)" class="delUser">封 停</button></td></tr>');
		
			}
		}	
	}
					
	function initUsers(){
		var url = "/HyperIT/userdetail/getAllUserInfo";
		var parm = "size=100&indexPageNum=1";
		$.get(url,parm,function(data){
			if(data.serviceResult){
				var usersList = data.resultParm.userDetail_list;
				showUsers(usersList);
				}
			else{
				alert(data.resultInfo);
			}
		});
	}
	
function delUser(which){
	var id = $(which).parent().parent().attr("id").split("_")[1];	
	var url =  "/HyperIT/userdetail/deleteUser";
	var parm = "id="+id;
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			alert(data.resultInfo);
			$(which).hide().prev().css("display","inline-block");
			$(which).parent().parent().children(".status").html("封 停");
		} else{
			alert(data.resultInfo);
		}
	});
}


function addUser(which){
	var id = $(which).parent().parent().attr("id").split("_")[1];	
	var url =  "/HyperIT/userdetail/unfreeze";
	var parm = "id="+id;
	$.get(url,parm,function(data){
		if (data.serviceResult) {
			alert(data.resultInfo);
			$(which).hide().next().css("display","inline-block");
			$(which).parent().parent().children(".status").html("正 常");
		} else{
			alert(data.resultInfo);
		}
	});
}



function search(){
	var find = $("#find").val();
	var url = "/HyperIT/userdetail/searchBlog";
	var parm = "size=2&search="+find+"&indexPageNum=1";
	$.get(url,parm,function(data){
		if(data.serviceResult){
			var userDetail_list = data.resultParm.userDetail_list;
			$("#usersList tr").eq(0).siblings().remove();
			showFind(userDetail_list);
		}
		else{
			alert(data.resultInfo);
		}
	})
}

function showFind(userDetail_list){
	for (var i=0;i<userDetail_list.length;i++){
			if(userDetail_list[i].status == 0){
				$("#usersList").append('<tr id="user_'+userDetail_list[i].id+'"><td>'+userDetail_list[i].name+'</td><td>'+userDetail_list[i].hb+'</td><td>'+userDetail_list[i].exp+'</td><td class="status">封 停</td><td><a href="userInfo.html?id='+userDetail_list[i].id+'"><button>详 情</button></a><button class="addUser" onclick="addUser(this)">解 封</button><button onclick="delUser(this)" class="delUser" style="display:none;">封 停</button></td></tr>');
			}else{
				$("#usersList").append('<tr id="user_'+userDetail_list[i].id+'"><td>'+userDetail_list[i].name+'</td><td>'+userDetail_list[i].hb+'</td><td>'+userDetail_list[i].exp+'</td><td class="status">正 常</td><td><a href="userInfo.html?id='+userDetail_list[i].id+'"><button>详 情</button></a><button class="addUser" onclick="addUser(this)" style="display:none;">解 封</button><button onclick="delUser(this)" class="delUser">封 停</button></td></tr>');
		
			}
		}	
}
